<template>
    <div class="song_list">
      
        <div class="list_title">
            <h3>最新歌曲推荐</h3>
            <i class="iconfont icon-gengduo" @click="song_all"></i>
        </div>
        
        <ul class="song_lists">
            <li v-if="index<moreNum" v-for="(item, index) in musicArr" :key="index">
                  <div class="song_img" @click="playMusic(index)">
                      <img :src="item.album_500_500" alt="">
                  </div>
                  <p class="song_name">{{item.album_title}}</p>
                  <p class="singer">{{item.artist_name}}</p>
            </li>
        </ul>
        <div class="more" @click="moreBtn">
          <p><i class="iconfont icon-icon04"></i></p>
          <p>加载更多</p>
        </div>
    </div>
</template>
<script>
import jsonp from "jsonp";
export default {
  name: "video_list",
  data() {
    return {
      musicArr: JSON.parse(sessionStorage.getItem("musicArr")),
      moreNum: "6"
    };
  },
  computed: {},
  methods: {
    playMusic(index) {
      this.$store.commit("agemusicArr", this.musicArr);
      this.$store.commit("agemusicArrIndex", index);
      this.$store.commit("ageisplayicon",true);
    },
    moreBtn() {
      this.moreNum = +this.moreNum + 3;
    },
    //弹出所有音乐
    song_all() {
      this.$router.push("/Music_list_all");
    }
  },
  components: {},
  created() {
    if (!this.musicArr) {
      jsonp(
        "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.billboard.billList&type=1&size=10&offset=0",
        null,
        (err, res) => {
          if (!err) {
            this.musicArr=res.song_list;
            sessionStorage.setItem("musicArr", JSON.stringify(res.song_list));
          } else {
            console.log(err);
          }
        }
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.song_list {
  width: 100%;
  margin-top: 0.1rem;
  background: #fff;
  padding-top: 0.6rem;
  margin-bottom: 1.7rem;

  .list_title {
    width: 100%;
    position: relative;
    text-align: center;
    height: 1rem;
    h3 {
      font-size: 15px;
      line-height: 1rem;
    }
    i {
      position: absolute;
      top: 0rem;
      right: 0.2rem;
      font-size: 0.6rem;
      line-height: 1rem;
    }
  }
  // 音乐列表
  .song_lists {
    width: 100%;
    overflow: hidden;
    margin-top: 0.3rem;
    li {
      display: inline-block;
      width: 33.333%;
      overflow: hidden;
      .song_img {
        width: 100%;
        height: 3rem;
        background: paleturquoise;
        overflow: hidden;
        img {
          width: 100%;
        }
      }
      > p {
        margin-left: 0.2rem;
        margin-top: 0.1rem;
        line-height: 0.6rem;
      }
      .song_name {
        font-size: 12px;
        overflow: hidden;
        white-space: nowrap; /*强制显示一行*/
        text-overflow: ellipsis; /*溢出文字省略号处理*/
        width: 80px;
        // display: -webkit-box;
      }
      .singer {
        font-size: 10px;
        color: #aaaaaa;
        overflow: hidden;
        white-space: nowrap; /*强制显示一行*/
        text-overflow: ellipsis; /*溢出文字省略号处理*/
        width: 80px;
      }
    }
    li:nth-of-type(3n-1) {
      padding: 0 0.05rem;
      box-sizing: border-box;
      overflow: hidden;
    }
  }
  .more {
    width: 100%;
    background: #fff;
    padding: 0.3rem 0;
    border-top: 1px solid #f1f1f1;
    p {
      text-align: center;
      font-size: 0.2rem;
      color: #a4a4a4;
    }
  }

  .Mv_list_all {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
    transform: translateY(-100%);
  }
}
</style>
